
$(function(){

    // 课程选择  
    $.ajax({
        url:'./php/course.php',
        type:'post',
        dataType:"json"
    }).done((result)=>{
        console.log(result);
        let strs=template("cour",{result});
        // console.log(result)
        $("#course").html(strs);
    
    })

    //老师选择
    $.ajax({
        url:'./php/teacherPage.php',
        type:'post',
        dataType:"json"
    }).done((teach)=>{
        console.log(teach);
        let strs=template("tea",{teach});
        $("#teacher").html(strs);
      
    })


    $.ajax({
        url:'./php/vedioPage.php',
        type:'post',
        dataType:"json"
    }).done((result)=>{
        let strs=template("vedio",result);
        console.log("vedio:",result)
        $("#vtf").html(strs);
  
    }) 
   

})

// //刷新 表格加载
function reload(){
    $.ajax({
        url:'./php/vedioPage.php',
        type:'post',
        dataType:"json"
    }).done((result)=>{
        let strs=template("vedio",result);
        console.log("vedio:",result)
        $("#vtf").html(strs);
  
    }) 
}reload()


function Up(obj){
    console.log("审核通过 上架 status=3")
    var videoId=$(obj).val();
    console.log(videoId)
    var status=$(obj).attr("status");
    var data={
        "videoId":videoId,
        "status":status
    };
    data["videoId"] = videoId
    $.ajax({
        url:"./php/v_clickChange.php",
        type:"post",
        data:data,
        dataType:"json"
    }).done((result) =>{
        console.log(result);
        if(result.up){
            toastr.success("视频已上架");
            reload();
        }else{
            toastr.error("视频上架失败");
        }
    });

}

function Down(obj){
    console.log("视频下架 ststus=4")
    var videoId=$(obj).val();
    console.log(videoId)
    var status=$(obj).attr("status");
    var data={
        "videoId":videoId,
        "status":status
    };
    data["videoId"] = videoId
    $.ajax({
        url:"./php/v_clickChange.php",
        type:"post",
        data:data,
        dataType:"json"
    }).done((result) =>{
        console.log(result);
        if(result.down){
            toastr.success("视频已上架");
            reload();
        }else{
            toastr.error("视频上架失败");
        }
    });
}

function out(obj){
    console.log("驳回 未通过 status=1")
    var videoId=$(obj).val();
    console.log(videoId)
    var status=$(obj).attr("status");
    var data={
        "videoId":videoId,
        "status":status
    };
    data["videoId"] = videoId
    $.ajax({
        url:"./php/out.php",
        type:"post",
        data:data,
        dataType:"json"
    }).done((result) =>{
        console.log(result);
            toastr.success("视频已上架");
            reload();
 
    });
}

function go(obj){
    console.log("通过 审核通过 status=2" )
    var videoId=$(obj).val();
    console.log(videoId)
    var status=$(obj).attr("status");
    var data={
        "videoId":videoId,
        "status":status
    };
    data["videoId"] = videoId
    $.ajax({
        url:"./php/v_clickChange.php",
        type:"post",
        data:data,
        dataType:"json"
    }).done((result) =>{
        console.log(result);
        if(result.go){
            toastr.success("视频已上架");
            reload();
        }else{
            toastr.error("视频上架失败");
        }
    });

}

//查
function searchTeacherVid(){

}